package com.xz.coursearrange.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xz.coursearrange.entity.Classroom;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 */
public interface ClassroomDao extends BaseMapper<Classroom> {

//    查询某个教学楼下的教室列表
    @Select("select * from tb_classroom where teachbuild_no = #{teachbuildNo}")
    List<Classroom> selectByTeachbuildNo(@Param("teachbuildNo") String teachbuildNo);

    // 根据年级获取教学楼下的所有教室
    @Select("SELECT \n" +
            "    c.id AS classroom_id,\n" +
            "    c.classroom_no,\n" +
            "    c.classroom_name,\n" +
            "    c.teachbuild_no,\n" +
            "    c.capacity,\n" +
            "    c.attr,\n" +
            "    c.remark,\n" +
            "    c.deleted,\n" +
            "    c.create_time,\n" +
            "    c.update_time\n" +
            "FROM \n" +
            "    tb_classroom c\n" +
            "JOIN \n" +
            "    tb_location_info l ON c.teachbuild_no = l.teachbuild_no\n" +
            "WHERE \n" +
            "    l.grade_no = #{grade_no} \n" +
            "    AND c.deleted = 0 \n" +
            "    AND l.deleted = 0;\n")
    List<Classroom> selectByGradeNo(@Param("grade_no") String grade_no);

    @Select("SELECT \n" +
            "    c.id AS classroom_id,\n" +
            "    c.classroom_no,\n" +
            "    c.classroom_name,\n" +
            "    c.teachbuild_no,\n" +
            "    c.capacity,\n" +
            "    c.attr,\n" +
            "    c.remark,\n" +
            "    c.deleted,\n" +
            "    c.create_time,\n" +
            "    c.update_time\n" +
            "FROM \n" +
            "    tb_classroom c\n" +
            "LEFT JOIN \n" +
            "    tb_course_plan cp ON c.classroom_no = cp.classroom_no AND cp.class_time = #{classTime} AND cp.deleted = 0\n" +
            "WHERE \n" +
            "    c.attr = #{attr}\n" +
            "    AND c.deleted = 0\n" +
            "    AND cp.classroom_no IS NULL;")
    List<Classroom> selectByClassTimeAndCourseNo(@Param("classTime") String classTime, @Param("attr") String attr);
}
